/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BrowserPanel.java
 *
 * Created on Aug 28, 2010, 12:17:45 PM
 */

package org.apache.directory.http.client.ui;


import java.util.List;

import javax.swing.border.AbstractBorder;
import javax.swing.border.Border;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.plaf.basic.BasicBorders;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import org.apache.directory.http.client.ui.model.EntryNode;
import org.apache.directory.http.client.ui.model.EntryTableModel;
import org.apache.directory.shared.ldap.entry.Entry;


/**
 *
 * @author kayyagari
 */
public class BrowserPanel extends javax.swing.JPanel
{

    /** Creates new form BrowserPanel */
    public BrowserPanel()
    {
        initComponents();
        entryTree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
        entryTable.setRowHeight( entryTable.getRowHeight() + 1 );
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        dataPane = new javax.swing.JSplitPane();
        scrollTreePane = new javax.swing.JScrollPane();
        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode( "x", true );

        entryTree = new javax.swing.JTree( treeNode1, true );
        
        
        scrollTablePane = new javax.swing.JScrollPane();
        entryTable = new javax.swing.JTable();

        setLayout( new java.awt.BorderLayout() );

        dataPane.setDividerLocation( 160 );

        //entryTree.setModel( new javax.swing.tree.DefaultTreeModel( treeNode1 ) );
        scrollTreePane.setViewportView( entryTree );

        dataPane.setLeftComponent( scrollTreePane );

        scrollTablePane.setViewportView( entryTable );

        dataPane.setRightComponent( scrollTablePane );

        add( dataPane, java.awt.BorderLayout.CENTER );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSplitPane dataPane;
    private javax.swing.JTable entryTable;
    private javax.swing.JTree entryTree;
    private javax.swing.JScrollPane scrollTablePane;
    private javax.swing.JScrollPane scrollTreePane;


    // End of variables declaration//GEN-END:variables

    public javax.swing.JTable getEntryTable()
    {
        return entryTable;
    }


    public javax.swing.JTree getEntryTree()
    {
        return entryTree;
    }


    public void setRootDse( EntryNode root )
    {
        //EntryNode root = new EntryNode( entry );
        entryTree.setModel( new DefaultTreeModel( root, true ) );
    }


    public void addEntriesToTreeUnder( List<Entry> entries, EntryNode parent )
    {
        for( Entry e : entries )
        {
            EntryNode node = new EntryNode( e );
            node.setAllowsChildren( true );
            parent.add( node );
        }
    }
}
